﻿namespace FastEasy.Common.Extension
{
    /// <summary>
    /// 随机数
    /// </summary>
    public static class RandomCode
    {
        /// <summary>
        /// 创建一个4位随机验证码
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomCode()
        {
            int num = 4;
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // 根据需要修改字符集合
            Random random = new();
            char[] code = new char[num];

            for (int i = 0; i < num; i++)
            {
                code[i] = chars[random.Next(chars.Length)];
            }
            return new string(code);
        }
    }
}